<template>
	<view class="uni_box home">
		<navbar :title="type==1?'充币记录':'提币记录'" :yin="true">
		</navbar>
		<view class="content">
			<!-- 提现 -->
			<view class="list" v-if="type == 2">
				<view class="item" v-for="(item,index) in list" :key="index">
					<view class="litem">
						<text class="name">{{item.network}}</text>
						<text class="name">{{item.symbol}}</text>
						<text class="time">{{timestampToTime(item.created_at)}}</text>
					</view>
					<text class="rnum">+{{ item.total_money }}</text>
				</view>
			</view>
			<!-- 充币 -->
			<view class="list" v-if="type == 1">
				<view class="item" v-for="(item,index) in list" :key="index">
					<view class="litem">
						<text class="name">{{item.title}}</text>
						<!-- <text class="name">{{item.symbol}}</text> -->
						<text class="time">{{item.created_at}}</text>
					</view>
					<text class="rnum">+{{ item.amount }}</text>
				</view>
			</view>

			<view class="nodata" v-if="list == ''">
				<u-empty text="暂无数据" mode="list"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type:'1',//1充币记录 2提币记录
				
				list: [],
				page: 1,
				last_page: 1,
				limit: 10,
				status: 'loadmore',
			}
		},
		onLoad(option) {
			this.type = option.type
			this.getList()
		},
		onShow() {
		},
		onReachBottom: function() {
			if(this.type == 2){
				this.loadmore();
			}
			
		},
		methods: {
			async getList(){
				if(this.type == 2){
					//提现
					let list = await this.$u.api.withdrawRecord({
						page:this.page,
						limit:this.limit
					});
					console.log(list)
					this.last_page = list.last_page;
					this.list = this.page == 1 ? list.data : [...this.list, ...list.data];
					if (this.last_page == this.page || list.data == '') {
						this.status = 'nomore';
					}
				}else if(this.type == 1){
					//充币
					let list = await this.$u.api.rechange_log({
					});
					
					this.list = list.data||[]
					// console.log(this.list)
				}
				
			},
			loadmore() {
				let page = this.page;
				let last_page = this.last_page;
				if (page < last_page) {
					this.page++;
					this.getList();
				}
			},

			timestampToTime(timestamp) {
				const date = new Date(Number(timestamp))
				const Y = date.getFullYear() + '/'
				const M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '/'
				const D = (date.getDate() < 10 ? '0'+(date.getDate()) : date.getDate()) + ' '
				const h = (date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours()) + ':'
				const m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':'
				const s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds())
				return Y+M+D+h+m+s
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.nodata{
		margin: 30% auto;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.content{
		background-color: #fff;
		padding: 30rpx 30rpx;
		.list{
			.item{
				border-bottom: 2rpx solid #F7F7F7;;
				padding: 20rpx 00rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				.rnum{
					margin-left: auto;
					font-family: Source Han Sans CN;
					font-weight: bold;
					font-size: 30rpx;
					color: #32BE67;
				}
				.litem{
					max-width: 80%;
					display: flex;
					flex-direction: column;

				}
				.name{
					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 24rpx;
					color: #000000;
					display: inline-block;
					margin-bottom: 8rpx;
				}
				.time{
					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 20rpx;
					color: #000000;
				}
				.nei{
					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 26rpx;
					color: #000000;
				}
				.miao{
					display: block;
					margin-top: 15rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 22rpx;
					color: #666666;
				}
			}
		}
		// padding-bottom: 150rpx;
	}
</style>
